/*-------------------------------------
		sPlugin
	    By Scooby, 2010
-------------------------------------*/

local PLUGIN = {}

PLUGIN.Name = "Slap"
PLUGIN.Author = "Scooby"
PLUGIN.Command = "slap"
PLUGIN.Group = 2
PLUGIN.Category = "Punishment"
PLUGIN.Format = "string number"
PLUGIN.Use = "<Player> <Damage>"
PLUGIN.Menu = {
	{
		title = "Choose Player",
		cont = "#players",
		apos = 1
	},
	{
		title = "Choose Damage",
		cont = "#number",
		apos = 2
	}
}

function PLUGIN:Main( ply, args )
	
	local pl = spl:FindPly( args[1] )
	local dam = tonumber( args[2] ) or 1
	local tmp = math.random( 1, 3 )
	local sound = ""
	local vol = math.Clamp( dam * 5, 300, 500 )
	
	
	if( dam > 60 ) then
		sound = "physics/body/body_medium_break"..math.random( 1, 4 )..".wav"
	elseif( dam > 30 ) then
		sound = "physics/body/body_medium_impact_hard"..math.random( 1, 6 )..".wav"
	else
		sound = "physics/body/body_medium_impact_soft"..math.random( 1, 4 )..".wav"
	end
	
	if( dam < 0 ) then
		spl:PrintC( ply, spl.red, "Cannot Slap With Negative Damage" )
		return false
	end
	
	
	if( #pl == 0 ) then
		spl:PrintC( ply, spl.red, spl.fnp )
		return false
	elseif( #pl > 1 ) then
		spl:PrintC( ply, spl.red, spl.fmp )
		return false
	end
	
	pl[1]:EmitSound( sound, vol )
	if( tmp == 1 ) then
		pl[1]:SetVelocity( pl[1]:GetRight() + Vector( 500, -300, 250 ) )
	elseif( tmp == 2 ) then
		pl[1]:SetVelocity( pl[1]:GetForward() + Vector( 500, 300, 250 ) )
	else
		pl[1]:SetVelocity( pl[1]:GetUp() + Vector( -500, 300, 250 ) )
	end
	
	if( pl[1]:Health() - dam < 1 ) then 
		pl[1]:Kill()
	else
		pl[1]:SetHealth( pl[1]:Health() - dam )
		pl[1]:ViewPunch( Angle( dam * -2, dam * -3, 0 ) )
	end
	
	spl:PrintC( spl.red, pl[1]:Nick(), spl.white, " Was Slapped By ", spl.blue, ply:Nick(), spl.white, " With ", spl.green, tostring( dam ), spl.white, " Damage" )
		
end


spl:AddPlugin( PLUGIN )